User management
User Management
User management includes online user management and local user management.
Online user data distinguishes different groups with enterprise number. Users in each group do not interfere with each other, and the groupID is the unique identification ID.
Offline User Data is stored in the robot body and can be used when online users are not turned on and there is no network.
It will actively obtain online or offline status when user management is started for the first time. Either online or offline must be selected, and the data is not interconnected. When you create an enterprise, online user management is enabled by default, and the groupID of the enterprise is generated. If you need to switch to offline user management, please contact the UBT technical support engineer.
Online user management and offline user management query user information method:
- In order to query the information of online users, it is necessary to provide face pictures or face feature values for face recognition through visual services. After recognition, the information of online users can be returned. For details, please refer to visual servicesface recognition interface .
- To query the offline user information, you can call the following interfaces
getusersandgetuserbyfaceidto return the user information. Whengetuserbyfaceidis called to query single user information, faceID is required. The face recognition interface of visual servicesmust be called before querying information to get faceID, then call thegetuserbyfaceidmethod to query individual user information.
Initialization
- Before using user management accesses the agent object,please initialize the usermanager object as follows:
UserManager userManager=UserManager.getInstance(this);
Get User Information
- Get all local users information :
userManager.getUsers(new UserListenrAbstract/*[1]*/(){ @Override public void getUsers(List<User> users/*[2]*/) { } });
[1] Userlistenrabstract is an abstract class that implements the usermanagerlistener interface. It implements callback listening by inheriting the userlistenrabstract class and overriding its method.
The interface call method of UserManagerListenr is as follows:
public interface UserManagerListenr { //Get all local users information void getUsers(List<User> users); //Get a local user information according to faceID void getUserByFaceId(User user); //Query user management status void getStatus(UserStatus status); }
[2] Users are the information collection of all local users queried. The user entity attributes are as follows:
public class User { private Long id; //Userid private String uuid; //User UUID private String faceId; //user faceId,used to recognization private String name; //User name private String title; //Title private int gender; //User gender 0:female 1:male 2:secrecy private List<Face> faces; //Face informaton [A person can have multiple face photos, and the corresponding information of each photo ] }
The properties of Face are as follows:
public class Face { private Long id; //id private String faceId; //User faceId private String path; //Picture path }
Note: the image path is a file encrypted by image, which can only be used after decryption. Please refer to the following file decryptionmethod.
- Query individual user information according to faceid:
userManager.getUserByFaceId/*[1]*/(mFaceId ,new UserListenrAbstract(){ @Override public void getUserByFaceId(User user/*[2]*/) { super.getUserByFaceId(user); Log.d("MainActivity","user:"+user); } });
[1]Parameter description of getUserByFaceId(String mFaceId,UserManagerListenr listenr)method :
| Parameter | Type | Explanation |
|---|---|---|
| mFaceId | String | User faceId(Each user has only one faceid, which is generated by visual services) when adding user information. Therefore, when using this interface, you should first call the face recognition interface of visual services to get the faceid) |
| listenr | UserManagerListenr | To callback listening,Please refer to get all local user information description. |
[2] Quering a local user information by the condition, for user entity property , please refer to: get all local user information entity description.
Get User Management Status
It is used to query whether user management is online or offline. If it is online user management, the corresponding groupid under the enterprise number of the robot will be returned. The groupid is used to distinguish the personnel information under different enterprise numbers. People in the user library of the same groupid are not allowed to be duplicate.User libraries of different groupids do not affect each other .
userManager.getStatus(new UserListenrAbstract(){ @Override public void getStatus(UserStatus status/*[1]*/) { } });
[1]Status refers to the status of user management (online / offline) and online groupid . The userstatus entity properties are as follows:
public class UserStatus{ private Boolean open;//Whether online user management open true:online user management open false:online user management is not open private String groupId; //return groupid when oline user management open,otherwise,return null }
File Decryption
InputStream inputStream /*[1]*/=userManager.decryptInputStream(String encryptFilePath/*[2]*/);
[1] [inputStream] is the input stream after the encrypted file is decrypted. You can take the stream to generate file. If it is the encrypted image path, the stream can directly transfer to bitmap to load the image:
InputStream decryptInputStream=userManager.decryptInputStream(encryptFilePath); Bitmap bitmap = BitmapFactory.decodeStream(decryptInputStream); ImageView imageView = findViewById(R.id.img); imageView.setImageBitmap(bitmap);
[2] EncryptFilePath is the path of the encrypted file,For example, the path property in the above Face entity
User registration
When a user registers a user through this interface, in order to maintain data consistency, the user data state flow is consistent with the state of user management. When user management is enabled for online user management, all users registered through this interface are online users. On the contrary, offline users are entered, and you can query the status through the above interface of Get User Management Status
java userManager.registerUser(user /*[1]*/,UserListenrAbstract(){ @Override public void register(int code /*[2]*/, String msg/*[3]*/) { } });
[1]userConsistent with the above User content, the structure is as follows:
java User user = new User.UserBuilder("Cruzr" /*Name*/, "/storage/emulated/0/Pictures/test2.png" /*The path of the picture*/) //Name and picture path are required .gender(0) .title("title") .build();
[2]code:
java SUCCESS = 0; //The storage is successful or the user information is found FAILED_CODE = -1; //Visual service disconnected INSERT_FAILED_CODE = -2; //Database storage failed INSERT_VISUAL_FAILED_CODE = -3; //Visual service feature value entry failed INTERRUPT_FAILED_CODE = -4; //Interrupted by next request
[3]msg:When code is not equal to 0, msg means error information, when code=0, msg means success or json data of user informationNote: For more vision-related codes, please check the corresponding codes in the vision service